package @{ctrlPkg};

import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.zzwtec.common.util.BeanUtil;
import com.zzwtec.common.util.CommonUtil;
import com.zzwtec.information.InformationServerApplication;
import @{modelPkg}.@{EntityModel};
import com.zzwtec.interfaces.Page;
import com.zzwtec.interfaces.RequestObject;
import com.zzwtec.interfaces.ResultObject;
import @{dtoPkg}.@{EntityModel}DTO;
import com.zzwtec.information.dao.@{EntityModel}Dao;
import @{servicePkg}.@{EntityModel}Service;


<?
var date = date();
?>


/**
 * @{EntityModel}Controller测试类
 * @author  草原狼
 *
 * @{date,'yyyy年MM月dd日'}
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = {InformationServerApplication.class})
public class @{EntityModel}ControllerTest {
	@Autowired
	@{EntityModel}Service @{entityModel}Service;
	
	@Autowired
	@{EntityModel}Dao dao;
	
	@Before
	//前置方法
	public  void test_before(){
		
	}	
	@After
	//后置方法
	public  void test_after(){
		
	}
	
	@Test
    public void test_add@{EntityModel}() {
    	//准备测试数据
    	@{EntityModel} adm = dao.selectOne("11111111111111111111");	
    	@{EntityModel}DTO dto = new @{EntityModel}DTO();
		BeanUtil.copyProperties(dto, adm);
		dao.deleteById("11111111111111111111");
		
		//开始测试
		RequestObject<@{EntityModel}DTO> request = new RequestObject<@{EntityModel}DTO>();
		request.setRequestId(CommonUtil.getUUID());
		request.setData(dto);		
		ResultObject<String> result = @{entityModel}Service.add@{EntityModel}(request);
		
		//断言
		assert("0".equals(result.getCode()));
	}
	
	@Test
    public void test_modify@{EntityModel}() {
    	//准备测试数据
    	@{EntityModel} adm = dao.selectOne("1111111111111");	
    	@{EntityModel}DTO dto = new @{EntityModel}DTO();
		BeanUtil.copyProperties(dto, adm);
		
		//开始测试
		RequestObject<@{EntityModel}DTO> request = new RequestObject<@{EntityModel}DTO>();
		request.setRequestId(CommonUtil.getUUID());
		request.setData(dto);	
		ResultObject<Void> result = @{entityModel}Service.modify@{EntityModel}(request);
		//断言
		assert("0".equals(result.getCode()));
	}
	
	@Test
    public void test_query@{EntityModel}ById() {
    	RequestObject<String> request = new RequestObject<String>();
		request.setRequestId(CommonUtil.getUUID());
		request.setData("1111111111111");
		ResultObject<@{EntityModel}DTO> result = @{entityModel}Service.query@{EntityModel}ById(request);
		//断言
		assert("0".equals(result.getCode()));
		assert(result.getData() != null);
	}
	
	@Test
    public void test_query@{EntityModel}ByPage() {
    	RequestObject<Page<@{EntityModel}DTO>> request = new RequestObject<Page<@{EntityModel}DTO>>();
		request.setRequestId(CommonUtil.getUUID());
		Page<@{EntityModel}DTO> page = new Page<@{EntityModel}DTO>();
		page.setPage(1);
		page.setPageNum(12);
		request.setData(page);		
		ResultObject<Page<@{EntityModel}DTO>> result = @{entityModel}Service.query@{EntityModel}ByPage(request);
	    //断言	
		assert("0".equals(result.getCode()));
		assert(result.getData().getData().size() == 12);
	}
	
	@Test
    public void test_queryAll@{EntityModel}() {
    	RequestObject<Void> request = new RequestObject<Void>();
		ResultObject<List<@{EntityModel}DTO>> result = @{entityModel}Service.queryAll@{EntityModel}(request);
		//断言	
		assert("0".equals(result.getCode()));
		assert(result.getData().size() > 0);
	}
	
	
	@Test
    public void test_remove@{EntityModel}() {
    	@{EntityModel} adm = dao.selectOne("1111111111111");
		RequestObject<String> request = new RequestObject<String>();
		request.setRequestId(CommonUtil.getUUID());
		request.setData("1111111111111");
		ResultObject<Void> result = @{entityModel}Service.remove@{EntityModel}(request);
		//断言
		assert("0".equals(result.getCode()));
		//补偿数据
		dao.insert(adm);
	}
	
	@Test
    public void test_remove@{EntityModel}ByIds() {
    	//准备测试数据
    	@{EntityModel} entity1 = dao.selectOne("1111111111111");
    	@{EntityModel} entity2 = dao.selectOne("2222222222222");
		
		RequestObject<String[]> request = new RequestObject<String[]>();
		request.setRequestId(CommonUtil.getUUID());
		request.setData(new String[]{entity1.getId(),entity2.getId()});

		ResultObject<Void> result = @{entityModel}Service.remove@{EntityModel}ByIds(request);
		//断言
		assert("0".equals(result.getCode()));
		//补偿数据
		dao.insert(entity1);
		dao.insert(entity2);
	}

	
}
